<template>
  <div class="setting">
    <el-card>
      <el-tabs>
        <el-tab-pane label="角色管理">
          <el-button type="primary" @click="add">+新增角色</el-button>
          <el-table :data="list">
            <el-table-column label="序号">
              <template v-slot="{ $index }">
                <div>
                  {{ (page.page - 1) * page.pagesize + $index + 1 }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              sortable
              label="角色名"
              prop="name"
            ></el-table-column>
            <el-table-column
              sortable
              label="描述"
              prop="description"
            ></el-table-column>
            <el-table-column label="操作">
              <template v-slot="{ row }">
                <div>
                  <el-button type="text">分配权限</el-button>
                  <el-button type="text" @click="edit(row)">修改</el-button>
                  <el-button type="text" @click="del(row)">删除</el-button>
                </div>
              </template>
            </el-table-column>
          </el-table>
          <div>
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="page.page"
              :page-sizes="[1, 10, 100, 200, 300, 400]"
              :page-size="page.pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="page.total"
            >
            </el-pagination>
          </div>
        </el-tab-pane>
        <!-- 公司信息 -->
        <el-tab-pane label="公司信息">
          <el-form label-width="250px">
            <el-form-item label="企业名称">
              <el-input
                disabled
                style="width:400px"
                placeholder="江苏传智博客教育科技股份有限公司"
              ></el-input>
            </el-form-item>
            <el-form-item label="公司地址">
              <el-input
                disabled
                style="width:400px"
                placeholder="北京市昌平区建材城西路金燕龙办公楼一层"
              ></el-input>
            </el-form-item>
            <el-form-item label="公司电话">
              <el-input
                disabled
                style="width:400px"
                placeholder="400-618-9090"
              ></el-input>
            </el-form-item>
            <el-form-item label="邮箱">
              <el-input
                disabled
                style="width:400px"
                placeholder="bd@itcastcn"
              ></el-input>
            </el-form-item>
            <el-form-item label="备注">
              <el-input
                disabled
                style="width:400px"
                placeholder="传智博客官网-好口碑IT培训机构，一样的教育，不一样"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <!-- <DialogitemIt v-model="show"></DialogitemIt> -->
    <DialogitemIt
      :isShow.sync="show"
      :list="list"
      @handleCurrentChange="handleCurrentChange"
      @getData="getData"
      ref="dialogitemIt"
    ></DialogitemIt>
  </div>
</template>

<script>
import { sysRole, sysRoleDel } from '@/api/setting'
import DialogitemIt from './components/dialogitem.vue'
export default {
  components: {
    DialogitemIt
  },
  data () {
    return {
      show: false,
      page: {
        page: 1,
        pagesize: 10,
        total: 100
      },
      list: []
    }
  },
  created () {
    this.getData()
  },
  methods: {
    async getData () {
      const res = await sysRole(this.page)
      this.list = res.data.rows
      this.page.total = res.data.total
      console.log('这个菜鸡，垃圾', res)
    },
    handleCurrentChange (page) {
      this.page.page = page
      this.getData()
    },
    handleSizeChange (size) {
      this.page.pagesize = size
      this.page.page = 1
      this.getData()
    },
    add () {
      this.show = true
      this.$refs.dialogitemIt.mode = 'add'
    },
    // 删除功能
    del (row) {
      this.$confirm('您确定删除该条数据', '提示')
        .then(async () => {
          await sysRoleDel(row.id)
          this.$message.success('删除成功')
          this.handleCurrentChange(1)
        })
        .catch(() => {})
    },
    edit (row) {
      // 编辑步骤 1.打开弹框 2.数据回显 3.加入一个参数用于区分新增和编辑 4.表单验证处理
      // 5.调用编辑接口 6.调用完成关闭弹窗，刷新数据，提示
      this.show = true
      this.$refs.dialogitemIt.form = JSON.parse(JSON.stringify(row))
      this.$refs.dialogitemIt.mode = 'edit'
    }
  }
}
</script>

<style lang="scss" scoped>
.setting {
  padding: 15px;
}
</style>
